package com.zbj.homemade;

import com.zbj.homemade.mybatis.DefaultSqlSessionFactory;
import com.zbj.homemade.mybatis.SqlSession;
import com.zbj.homemade.mybatis.SqlSessionFactory;
import com.zbj.homemade.mybatis.conf.Configuration;
import com.zbj.homemade.mybatis.test.TestMapper;
import com.zbj.homemade.mybatis.test.TestModel;

import java.util.List;

/**
 * @program: principle
 * @description:
 * @author: Yinn
 * @create: 2019-01-14 14:54
 **/
public class MybatisMain {

    public static void main(String args[]) throws ClassNotFoundException {

        //因为没有接入spring 框架 所以扫描和配置的地方 用main函数的方式代替 偷懒

        Configuration configuration = new Configuration();
        configuration.setUsername("root");
        configuration.setPassword("yinnan");
        configuration.setUrl("jdbc:mysql://localhost:3306/lagou_job?useUnicode=true&amp;characterEncoding=UTF8");
        configuration.setDriver("com.mysql.jdbc.Driver");

        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration,"com.zbj.homemade.mybatis.test");

        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        TestMapper proxyTestMapper = sqlSession.getMapper(TestMapper.class);
        List<TestModel> result = proxyTestMapper.queryTestList("1023");

        if (result != null && result.size() > 0)
            System.out.println(result.get(0));


    }
}
